﻿using System;
using System.Collections.Generic;
using System.Text;
using TTServer.Messages;
using libCommonClass;
using DrawingScreen;
using DrawingScreen.Messages;

namespace TTServer
{
    public class MessageFactory
    {
        private static MessageFactory _instance = null;

        public static MessageFactory GetInstance()
        {
            try
            {
                if (_instance == null)
                {
                    _instance = new MessageFactory();
                    _instance.Init();
                }

                return _instance;
            }
            catch
            {
                return null;
            }
        }

        private List<TTMessage> list = new List<TTMessage>();

        public void Add(TTMessage msg)
        {
            list.Add(msg);
        }

        public TTMessage CreateMessage(int MessageID)
        {

            for (int i = 0; i < list.Count; i++)
            {
                TTMessage msg = list[i];

                if (msg != null)
                {
                    int id = msg.GetMessageID();
                    
                    if (id == MessageID)
                    {
                        return msg.Clone();
                    }
                }
            }

            return null;
        }

        public bool Init()
        {
            // Độ ưu tiên cao
            _instance.Add(new CDrawingMessage_Action());

            // static runtime initialization
            _instance.Add(new AdminAuthentificationRequestMessage());
            _instance.Add(new AdminAuthentificationResponseMessage());
            _instance.Add(new FileExploreRequestMessage());
            _instance.Add(new FileExploreResponseMessage());
            _instance.Add(new PPTGoToSlideRequestMessage());
            _instance.Add(new NMSAuthentificationRequestMessage());
            _instance.Add(new NMSAuthentificationResponseMessage());
            _instance.Add(new NotifyMessage());
            _instance.Add(new SlideChangedMessage());
            _instance.Add(new PPTSlideShowDataRequestMessage());
            _instance.Add(new SlideshowDataResponseMessage());
            _instance.Add(new NextSlideMessage());
            _instance.Add(new PrevSlideMessage());
            _instance.Add(new StartSlideshowMessage());
            _instance.Add(new EndSlideshowMessage());
            _instance.Add(new ToggleBlackScreenMessage());
            _instance.Add(new ClearDrawingMessage());
            _instance.Add(new SignOutRequestMessage());
            _instance.Add(new SignOutResponseMessage());
            _instance.Add(new ResetNMSAuthentificationMessage());
            _instance.Add(new RSAPublicKeyClientMessage());
            _instance.Add(new PPTOpenFileRequestMessage());
            _instance.Add(new PPTOpenFileResponseMessage());
            _instance.Add(new PPTMaximizeWindowRequestMessage());
            _instance.Add(new PPTMinimizeWindowRequestMessage());
            _instance.Add(new PPTLaunchPowerpointRequestMessage());
            _instance.Add(new PPTQuitPowerpointRequestMessage());
            _instance.Add(new PPTCloseFileRequestMessage());
            _instance.Add(new PPTCloseAllFilesRequestMessage());
            _instance.Add(new PPTShowDrawingScreenRequestMessage());
            _instance.Add(new PPTHideDrawingScreenRequestMessage());
            _instance.Add(new PPTWindowsRelationshipRequestMessage());
            _instance.Add(new PPTActivateWindowRequestMessage());
            _instance.Add(new PPTEnableBroadcastingRequestMessage());
            _instance.Add(new PPTDisableBroadcastingRequestMessage());
            _instance.Add(new MouseMoveMessage());
            _instance.Add(new MouseClickMessage());
            _instance.Add(new PPTSlideShowClickMessage());
            _instance.Add(new PPTBlackScreenRequestMessage());
            _instance.Add(new PPTWhiteScreenRequestMessage());
            _instance.Add(new DSOpenFileRequestMessage());
            _instance.Add(new DSOpenFileResponseMessage());
            _instance.Add(new DSLoadRequestMessage());
            _instance.Add(new DSSaveRequestMessage());

            _instance.Add(new KeyMemberAuthentificationRequestMessage());
            _instance.Add(new KeyMemberAuthentificationResponseMessage());

            _instance.Add(new ScreenSizeRequestMessage());
            _instance.Add(new ScreenSizeResponseMessage());

            _instance.Add(new FileDetailsRequestMessage());
            _instance.Add(new FileDetailsResponseMessage());

            _instance.Add(new CDrawingMessage_Bezier());
            _instance.Add(new CDrawingMessage_ChangeColor());
            _instance.Add(new CDrawingMessage_Circle());
            _instance.Add(new CDrawingMessage_Ellipse());
            _instance.Add(new CDrawingMessage_Freedom());
            _instance.Add(new CDrawingMessage_Line());
            _instance.Add(new CDrawingMessage_Freedom());
            _instance.Add(new CDrawingMessage_Line());
            _instance.Add(new CDrawingMessage_Pointer());
            _instance.Add(new CDrawingMessage_Rectangle());
            _instance.Add(new CDrawingMessage_Redo());
            _instance.Add(new CDrawingMessage_Undo());
            _instance.Add(new CDrawingMessage_ChangeWidth());
            _instance.Add(new CDrawingMessage_Clear());
            _instance.Add(new CDrawingMessage_ClipArt());
            _instance.Add(new CDrawingMessage_Clear_Current_Slide());
            _instance.Add(new CDrawingMessage_Clear_All_Slides());

            //dynamic runtime initialization

            return true;
        }
    }
}
